package repository

import (
	"rustdesk_api_server/global"
	"rustdesk_api_server/models"
)

var Tags = new(TagRepository)

type TagRepository struct{}

func (tag *TagRepository) DeleteAll(user models.User) error {
	return global.DB.Where("user_id = ?", user.ID).Delete(&models.Tags{}).Error
}

func (tag *TagRepository) Updates(tags []models.Tags) error {
	return global.DB.Create(tags).Error
}

func (tag *TagRepository) GetByUserId(user_id uint) []models.Tags {
	var tags []models.Tags
	err := global.DB.Find(&tags, "user_id = ?", user_id).Error
	if err != nil {
		return nil
	} else {
		return tags
	}
}
